package com.lj.infoisland.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lj.infoisland.common.convention.result.Result;
import com.lj.infoisland.common.convention.result.Results;
import com.lj.infoisland.domain.common.CommonOption;
import com.lj.infoisland.domain.po.NewsCategories;
import com.lj.infoisland.domain.po.UserFavorites;
import com.lj.infoisland.domain.vo.UserInfoVO;
import com.lj.infoisland.mapper.NewsCategoriesMapper;
import com.lj.infoisland.service.NewsCategoriesService;
import com.lj.infoisland.service.UserFavoritesService;
import com.lj.infoisland.util.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/*
 * @description 新闻分类服务类实现类
 * @author 龙洁
 * @create 2024-10-21 下午10:42
 */
@Service
@RequiredArgsConstructor
public class NewsCategoriesServiceImpl extends ServiceImpl<NewsCategoriesMapper, NewsCategories> implements NewsCategoriesService {

    @Override
    public Result<List<CommonOption>> getNewsCategoriesList() {
        List<CommonOption> commonOptions = new ArrayList<>();
        LambdaQueryWrapper<NewsCategories> wrapper = Wrappers.lambdaQuery(NewsCategories.class);
        List<NewsCategories> newsCategories = baseMapper.selectList(wrapper);
        newsCategories.forEach(item -> {
            commonOptions.add(new CommonOption(item.getId(), item.getName()));
        });
        return Results.success(commonOptions);
    }

    @Override
    public Result<List<NewsCategories>> getNewsCategoriesAdminList() {
        LambdaQueryWrapper<NewsCategories> wrapper = Wrappers.lambdaQuery(NewsCategories.class);
        return Results.success(baseMapper.selectList(wrapper));
    }

    @Override
    public void deleteNewsCategories(Integer id) {
        baseMapper.deleteById(id);
    }

    @Override
    public void addNewsCategories(String name) {
        NewsCategories newsCategories = new NewsCategories();
        newsCategories.setName(name);
        baseMapper.insert(newsCategories);
    }

}
